// 导入组件
import Vue from 'vue';
import Router from 'vue-router';

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 启用路由
Vue.use(Router);
import managPublicLayout from "../views/manageSysExamplePublicLayout/index.vue";
import manageSysPublic from "./modules/manageSysPublic";
import manageSysExample from "./modules/manageSysExample";
import manageSysCharts from "./modules/manageSysCharts"

export const constantRoutes = [
    {
        path: "/",
        component: managPublicLayout,
        redirect: "/dashboard",
        children: [{
            path: "dashboard",
            component: () =>
                import ("@/views/index/index"),
            name: "Dashboard",
            meta: { title: "首页", icon: "dashboard", affix: true }
        }]
    },
    {
        path: "/login",
        component: () =>
            import ("@/views/manageSysExamplePublicLogin/index"),
    },
    {
        path: "/redirect",
        component: managPublicLayout,
        hidden: true,
        children: [{
            path: "/redirect/:path*",
            component: () =>
                import ("@/views/redirect/index")
        }]
    },
    {
      path: "/edit_system_user",
      component: managPublicLayout,
      redirect: "/edit_system_user/index",
      hidden: true,
      children: [{
          path: "index",
          component: () =>
              import ("@/views/manageSysUser/page/edit_system_user/index"),
          name: "添加系统用户",
          meta: {
              title: "添加系统用户",
              icon: "user",
              noCache: true
          }
      }]
    },   
    {
        path: "/add_resource",
        component: managPublicLayout,
        redirect: "/add_resource/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysResource/page/edit_resource/index"),
            name: "添加资源",
            meta: { title: "添加资源", icon: "user", noCache: true }
        }]
    },
    {
        path: "/edit_resource",
        component: managPublicLayout,
        redirect: "/edit_resource/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysResource/page/edit_resource/index"),
            name: "编辑资源",
            meta: { title: "编辑资源", icon: "user", noCache: true }
        }]
    },
    {
        path: "/add_role",
        component: managPublicLayout,
        redirect: "/add_role/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysRole/page/edit_role/index"),
            name: "添加角色",
            meta: { title: "添加角色", icon: "user", noCache: true }
        }]
    },
    {
        path: "/edit_role",
        component: managPublicLayout,
        redirect: "/edit_role/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysRole/page/edit_role/index"),
            name: "编辑角色",
            meta: { title: "编辑角色", icon: "user", noCache: true }
        }]
    },
    {
        path: "/add_menu",
        component: managPublicLayout,
        redirect: "/add_menu/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysMenu/page/edit_menu/index"),
            name: "添加菜单",
            meta: { title: "添加菜单", icon: "user", noCache: true }
        }]
    },
    {
        path: "/edit_menu",
        component: managPublicLayout,
        redirect: "/edit_menu/index",
        hidden: true,
        children: [{
            path: "index",
            component: () =>
                import ("@/views/manageSysMenu/page/edit_menu/index"),
            name: "编辑菜单",
            meta: { title: "编辑菜单", icon: "user", noCache: true }
        }]
    },
    
    manageSysPublic,
    manageSysExample,
    manageSysCharts

];

export const asyncRoutes = [
    // { path: "*", redirect: "/404", hidden: true }
];


// 导出路由 
const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})



const router = createRouter()


export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}



export default router